package com.affectu.user;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;

import org.hibernate.validator.Email;
import org.hibernate.validator.Length;
import org.jboss.seam.annotations.Name;

import com.affectu.common.base.EntityBase;
import com.affectu.message.Message;
import com.affectu.task.Bid;
import com.affectu.task.InnerTask;

/*
 * 2008-8-10 
 * @author daniel nathan 
 */
@Entity
@Name("user")
public class User extends EntityBase implements Serializable {

	private static final long serialVersionUID = 5205535615590080359L;
	// @Pattern(regex =
	// "^([0-9a-zA-Z]+[_.0-9a-zA-Z-]+)@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2,3})$",
	// message = "Email格式不正确.")
	@Email(message = "Email格式不正确.")
	private String email;
	@Length(min = 4, message = "长度少于4个字符.")
	private String password;
	private transient String passwordConfirm;
	private String faceImage;
	@Length(max = 255)
	private String nickName;
	private String trueName;
	private String gender;
	private Date birthday;
	private String address;
	private String language;
	private String languageLevel;
	private String telephone;
	private String mobilePhone;
	private String qq;
	@Length(max = 1023)
	private String specialty;
	private String webSite;
	private transient String checkCode;

	@OneToMany(mappedBy = "owner")
	private List<InnerTask> ownTasks;// 获取其所有发布项目

	@OneToMany(mappedBy = "owner")
	private List<Bid> allBid;// 获取其所有的投标

	@OneToMany(mappedBy = "sender")
	private List<Message> sendMessages;// 其发送的所有消息

	@ManyToMany(mappedBy = "receivers")
	private List<Message> reveivedMessages;// 其收到的所有消息

	@ManyToMany(mappedBy = "fromVistors")
	private List<User> toVistors;// 访问其他用户

	@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
	@JoinTable(name = "ToVisitor_FromVistor", joinColumns = { @JoinColumn(name = "fromVistorId", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "toVisitorId", referencedColumnName = "id") })
	private List<User> fromVistors;// 被其他用户所访问

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(name = "Users_Roles", joinColumns = { @JoinColumn(name = "User_Id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "Role_Id", referencedColumnName = "id") })
	private List<Role> roles = new ArrayList<Role>();// 其所有的角色

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPasswordConfirm() {
		return passwordConfirm;
	}

	public void setPasswordConfirm(String passwordConfirm) {
		this.passwordConfirm = passwordConfirm;
	}

	public String getFaceImage() {
		return faceImage;
	}

	public void setFaceImage(String faceImage) {
		this.faceImage = faceImage;
	}

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public String getTrueName() {
		return trueName;
	}

	public void setTrueName(String trueName) {
		this.trueName = trueName;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public Date getBirthday() {
		return birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public String getLanguageLevel() {
		return languageLevel;
	}

	public void setLanguageLevel(String languageLevel) {
		this.languageLevel = languageLevel;
	}

	public String getTelephone() {
		return telephone;
	}

	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}

	public String getMobilePhone() {
		return mobilePhone;
	}

	public void setMobilePhone(String mobilePhone) {
		this.mobilePhone = mobilePhone;
	}

	public String getQq() {
		return qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	public String getSpecialty() {
		return specialty;
	}

	public void setSpecialty(String specialty) {
		this.specialty = specialty;
	}

	public String getWebSite() {
		return webSite;
	}

	public void setWebSite(String webSite) {
		this.webSite = webSite;
	}

	public String getCheckCode() {
		return checkCode;
	}

	public void setCheckCode(String checkCode) {
		this.checkCode = checkCode;
	}

	public List<InnerTask> getOwnTasks() {
		return ownTasks;
	}

	public void setOwnTasks(List<InnerTask> ownTasks) {
		this.ownTasks = ownTasks;
	}

	public List<Bid> getAllBid() {
		return allBid;
	}

	public void setAllBid(List<Bid> allBid) {
		this.allBid = allBid;
	}

	public List<Message> getSendMessages() {
		return sendMessages;
	}

	public void setSendMessages(List<Message> sendMessages) {
		this.sendMessages = sendMessages;
	}

	public List<Message> getReveivedMessages() {
		return reveivedMessages;
	}

	public void setReveivedMessages(List<Message> reveivedMessages) {
		this.reveivedMessages = reveivedMessages;
	}

	public List<User> getToVistors() {
		return toVistors;
	}

	public void setToVistors(List<User> toVistors) {
		this.toVistors = toVistors;
	}

	public List<User> getFromVistors() {
		return fromVistors;
	}

	public void setFromVistors(List<User> fromVistors) {
		this.fromVistors = fromVistors;
	}

	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
}
